'''
Created on Apr 16, 2012
TC ID: Ecom_5016
Desc: Kiem thu chuc nang sua thong tin User
@author: lavang
'''
import unittest
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.loginPageFunc import login
from Functions.usersFunc import clickOnUsers, createUser,\
    isUserCreatedSuccessfully, clickOnLinkUser
from HTMLTestRunner import HTMLTestRunner
import time
from Functions.coursesFunc import clickOnUserName


username=readData("username")
password=readData("password")
tm_user=readData("users")
tm_lastName='Robin'
tm_avatar=readData("avatar")
tm_password=123456
tm_userType=readData("userType",index=2)
tm_language=readData("language")
tm_timeZone='(GMT +08:00) Singapore'
tm_comment='this is comment'

class Ecom_5016(unittest.TestCase):


    def setUp(self):
        preCondition(self)
        
    def test_Ecom_5016(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Click vao User"
        clickOnUsers(self)
        
        print "Buoc 3: Click vao user muon sua thong tin "
        clickOnUserName(self,tm_user)
        
        print "Buoc 4: Sua thong tin" # thay doi Last Name
        createUser(self,tm_avatar,tm_user,tm_password,tm_password,firstName=tm_user,lastName=tm_lastName,email='',userType=tm_userType,language=tm_language,timeZone=tm_timeZone,description='',comment=tm_comment,status='off',edit='on')
        
        print 'Buoc 5: Tro ve danh sach User' 
        clickOnLinkUser(self) 
        
        print "Buoc 6: Xac nhan sua thong tin User thanh cong"
        self.assertTrue(isUserCreatedSuccessfully(self,tm_lastName), "Failed! Sua thong tin User khong thanh cong")
        print "Passed: User duoc sua thong tin"
    
    def tearDown(self):
        endCondition(self)
        



if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5016)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin User'
                    )
    runner.run(suite)